package ${pkgName };

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ld.admin.controller.AdminBasicController;
import ${modelPackage!}.${modelName};
<% //自定义service %>
<% if ( isNotEmpty(serviceName) ) { %>
import org.springframework.beans.factory.annotation.Autowired;
import ${servicePackage!}.${serviceName};
<% } %>
import com.ld.shieldsb.annotation.duplicate.SubmitRequestIntercept;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;
import com.ld.shieldsb.dao.model.QueryModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * ${modelComments}
 * 
 * @ClassName ${className}
<% if ( isNotEmpty(email) ) { %>
 * @author <a href="mailto:${email}" target="_blank">${author!"无名氏"}</a>
<% } else { %>
 * @author ${author!"无名氏"}
<% } %>
 * @date ${nowTime}
 *
 */
<% //（此行为注释，不会输出到生成的代码中）modelComments为传递的参数 %>
@Api(tags = "${modelComments!}")
@Controller(value = "${has(controllerName)?controllerName:className}")
<% //（此行为注释，不会输出到生成的代码中）加上\转义 %>
@RequestMapping("\${shieldsb.adminPath}/${baseURL!}")
public class ${className} extends AdminBasicController<${modelName}> {
<% //自定义service %>
<% if ( isNotEmpty(serviceName) ) { %>
    @Autowired
    protected ${serviceName} ${serviceObjName};
<% } %>

    @ApiOperation(value = "首页", notes = "")
    @RequestMapping(path = "", method = RequestMethod.GET)
    public String index() {
        return "forward:" + adminPath + "/${baseURL!}/toSearch"; // 跳转搜索页面
    }

    @ApiOperation(value = "到搜索页面", notes = "")
    @RequestMapping(path = "/toSearch", method = RequestMethod.GET)
    public String toSearch() {
        return "${jspDir!}/${jspPrefix!}_search";
    }

    @ApiOperation(value = "搜索结果", notes = "")
    @RequestMapping(path = "/search", method = RequestMethod.POST)
    public String search() {
        QueryModel queryModel = ${serviceObjName!"basicService"}.getSearchQueryModel(request, getModelClass());
        ${serviceObjName!"basicService"}.getPageBean(request, getModelClass(), queryModel);
        return "${jspDir!}/${jspPrefix!}_list";
    }

    @ApiOperation(value = "${modelComments!}展示", notes = "")
    @RequestMapping(path = "/show", method = RequestMethod.GET)
    public String show() {
        long id = getLong("id");
        ${serviceObjName!"basicService"}.getOne(request, getModelClass(), id);
        return "${jspDir!}/${jspPrefix!}_show";
    }

    @ApiOperation(value = "跳转到添加/修改${modelComments!}", notes = "")
    @RequestMapping(path = "/toAddOrUpdate", method = RequestMethod.GET)
    public String toAddOrUpd() {
        long id = getLong("id");
        ${serviceObjName!"basicService"}.getOne(request, getModelClass(), id);
        return "${jspDir!}/${jspPrefix!}_update";
    }

    @ApiOperation(value = "添加/修改${modelComments!}", notes = "")
    @RequestMapping(path = "/addOrUpdate", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    @SubmitRequestIntercept(desp = "提交拦截验证")
    public Object addOrUpd(@Valid ${modelName} model) {
        Result result = ${serviceObjName!"basicService"}.addOrUpdate(model, model.getId() != null);
        return Web.Response.result(result);
    }
    
<% //有审核审核功能的 start %>
<% if ( hasAudit!false ) { %>
    @ApiOperation(value = "跳转到审核页面", notes = "")
    @RequestMapping(path = "/toAudit", method = RequestMethod.GET)
    public String toAudit() throws ServletException, IOException {
        long id = getLong("id");
        ${serviceObjName!"basicService"}.getOne(request, getModelClass(), id);
        request.setAttribute("audit", true);
        return "${jspDir!}/${jspPrefix!}_audit";
    }

    @ApiOperation(value = "审核${modelComments!}信息", notes = "")
    @RequestMapping(path = "/audit", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    @SubmitRequestIntercept(desp = "提交拦截验证")
    public Object audit(${modelName} model) throws ServletException, IOException {
        Result result = ${serviceObjName!"basicService"}.audit(model);
        return Web.Response.result(result);
    }
    
<% } %>
    @ApiOperation(value = "删除${modelComments!}", notes = "")
    @RequestMapping(path = "/del", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    public Object del() {
        long id = getLong("id");
        Result result = ${serviceObjName!"basicService"}.remove(getModelClass(), id);
        return Web.Response.result(result);
    }

}